﻿

$.MGJ.NodeAdd = [];


var times = 0;



(function () {
    var _this = $.MGJ.NodeAdd;
    $.extend($.MGJ.NodeAdd, {

        //添加节点
        Dialog_AEditNodeInfoObj: null,
        Dialog_AEditNodeInfo: function (type, obj, flowId) {

            if (times != 0) {
                return ;
            }

            times++;

            setTimeout(function () {


                times = 0;

            }, 2000);


            var nodeId = $(obj).attr("id");
            var EXTIsEnter = $(obj).attr("EXTIsEnter");
            if (EXTIsEnter == 1) {
                $.L.msgError("当前已超过录入次数限制，请联系管理员！");
                return;
            }
            var EXTIsPermission = $(obj).attr("EXTIsPermission");
            if (EXTIsPermission == 1) {
                $.L.msgError("您没有此节点的录入权限，请联系管理员！");
                return;
            }


      

            this.Dialog_AEditNodeInfoObj = $.L.dialog({
                url: ACTION_URL("AEditNodeInfo", "OriginsNode") + "?type=" + type + "&nodeId=" + nodeId + "&flowId=" + flowId,
                title: "添加节点",
                width: 700,
                height: 'auto',
                buttons: {
                    "button_save lak": {
                        type: 'primary',
                        text: '保存',
                        id:'NodeSave',
                        click: function () {
                         
                    
                            $.MGJ.NodeAdd.Ajax_NodeSave(_this);
                        }
                    },
                    "button_cancel": {
                        type: 'default',
                        text: '取消',
                        click: 'MODALMISS'
                    }
                },
            });
        },

        Dialog_EditNodeObj: null,
        Dialog_EditNode: function (nodeId) {

            //var batchId = $(obj).attr("batchId");
            //var productId = $(obj).attr("productId");

            this.Dialog_EditNodeObj = $.L.dialog({
                url: ACTION_URL("AEditNodeInfo", "OriginsNode") + "?type=edit&nodeId=" + nodeId + "&flowId=-1",
                title: "编辑节点",
                width: 700,
                height: 'auto',
                buttons: {
                    "button_save": {
                        type: 'primary',
                        text: '保存',
                        click: function () {
                            _this.Dialog_EditNodeObj.close();
                        }
                    },
                    "button_cancel": {
                        type: 'default',
                        text: '取消',
                        click: 'MODALMISS'
                    }
                }
            });

        },





        Dialog_AddNodeSelectObj: null,
        Dialog_AddNodeSelect: function (obj) {

            var batchId = $(obj).attr("batchId");

            this.Dialog_AddNodeSelectObj = $.L.dialog({
                url: ACTION_URL("AddNodeSelect", "OriginsNode") + "?batchId=" + batchId,
                title: "添加节点",
                width: 700,
                height: 'auto',
                buttons: {
                    "button_save": {
                        type: 'primary',
                        text: '保存',
                        click: function () {
                            _this.Dialog_AddNodeSelectObj.close();
                        }
                    },
                    "button_cancel": {
                        type: 'default',
                        text: '取消',
                        click: 'MODALMISS'
                    }
                }
            });

        },

        //$.MGJ.NodeAdd.EditNode





        Ajax_NodeSave: function (__this) {

            var NodeContent = $("#NodeContent").val();
            if (NodeContent == "") {
                alert("请填写内容");
                return;
            }

            var ImgUrl = $("#ImgUrl").val();
            var VideoUrl = $("#VideoUrl").val();
            if (ImgUrl == "" && VideoUrl == "") {
                alert("请检查图片或视频是否上传");
                return;
            }

            $('button[data-btnname="button_save lak"].btn.btn-primary').attr('disabled', "disabled");

            $.L.ajaxHandle({
                url: ACTION_URL("NodeSave", "OriginsNode"),
                data: $("#nodeForm").serialize(),
                success: function (ht) {
               
                    var batchId = $("#batchId").val();
                    $.MGJ.NodeAdd.Ajax_GetTempletNodeList(batchId);

                    if (ht.result > 0) {
                        if (ht.model.ImgUrl != "" && ht.model.ImgUrl != null) {

                            var html = "";
                            html += '<li class="padding-top-10 padding-bottom-10">'
                            html += '   <h1 class="EditLiH1">' + ht.model.NodeName + '</h1>'
                            html += '<span class="EditLiSpan">' + ht.model.NodeContent + '</span>'
                            html += ' <img class="EditVideoOrImg" src="' + ht.model.ImgUrl + '"></img>'
                            html += '<div class="EditLiBtnDiv">'
                            html += '<button class="btn btn-danger" onclick="$.MGJ.NodeAdd.Ajax_NodeDelete(this,' + ht.model.Id+ ')">删除</button>'
                            html += ' </div>'
                            html += '</li>';

                            $("#NodeInfoLeft2").append(html)
                            $.L.msgSuccess("操作成功！");

                            _this.Dialog_AEditNodeInfoObj.close();

                        }
                        if (ht.model.VideoUrl != "" && ht.model.VideoUrl != null) {

                            var html = "";
                            html += '<li class="padding-top-10 padding-bottom-10">'
                            html += '   <h1 class="EditLiH1">' + ht.model.NodeName + '</h1>'
                            html += '<span class="EditLiSpan">' + ht.model.NodeContent + '</span>'
                            html += ' <video class="EditVideoOrImg" src="' + ht.model.VideoUrl + '" controls="controls">您的浏览器不支持video</video>'
                            html += '<div class="EditLiBtnDiv">'
                            html += '<button class="btn btn-danger" onclick="$.MGJ.NodeAdd.Ajax_NodeDelete(this,' + ht.model.Id + ')">删除</button>'
                            html += ' </div>'
                            html += '</li>';

                            $("#NodeInfoLeft2").append(html)


                            //var html = '<li class="padding-top-10 padding-bottom-10"><h1 class="EditLiH1">' + ht.model.NodeName + '</h1><span class="EditLiSpan">' + ht.model.NodeContent + '</span><video class="EditVideoOrImg" src="' + ht.model.VideoUrl + '" controls="controls">您的浏览器不支持video</video></li>'
                            //$("#NodeInfoLeft").append(html)

                            _this.Dialog_AEditNodeInfoObj.close();
                            $.L.msgSuccess("操作成功！");

                        }
                    }
                }
            });
        },


        Ajax_NodeDelete: function (obj, nodeId) {

            var nodeId = nodeId;
            $.L.ajaxHandle({
                url: ACTION_URL("NodeDelete", "OriginsNode"),
                data: {
                    nodeId: nodeId
                },
                success: function (response) {
                    $.L.msgSuccess("操作成功");
                    $(obj).parents("li").remove();


                    var batchId = $("#batchId").val();
                    $.MGJ.NodeAdd.Ajax_GetTempletNodeList(batchId);
                }
            });

        },

        Ajax_GetTempletNodeList: function (batchId) {

            $.L.ajaxHandle({
                url: ACTION_URL("GetTempletNodeListContainPermission", "OriginsNode"),
                data: {
                    batchId: batchId
                },
                success: function (response) {
                    $("#TempletNodeList").L_bindingDataList(response);
                    if (response.length == 0) {

                        $("#TempletNodeList").append("<tr><td colspan='2'>节点尚未添加</td></tr>")
                    }
                }
            });
        },

        IsEnter: function (val) {

            if (val == 0) {
                return " ";
            } else {
                return "moretime"
            }

        },
        IsPermission: function (val) {

            if (val == 0) {
                return " ";
            } else {
                return "unable"
            }

        }

    });
})(jQuery);